﻿using System.Collections.Generic;
using System.Data.Common;
using com.kmer.enums;

namespace com.kmer.interfaces {
	public interface IFinanceFactory : IFactory {
		/// <summary>
		/// 获取当前用户的余额
		/// </summary>
		/// <returns></returns>
		IBalance GetMyBalance();

		/// <summary>
		/// 获取指定用户的余额
		/// </summary>
		/// <param name="CusId"></param>
		/// <returns></returns>
		IBalance GetBalance(int CusId);

		/// <summary>
		/// 添加日志
		/// </summary>
		/// <param name="CusId">账户变动的用户</param>
		/// <param name="Type">变动类型，单数为增加，偶数为减少</param>
		/// <param name="Amount">金额（无论增减都是正数）</param>
		/// <param name="Currentcy">货币类型（0x1-线上，0x2-线下，0x4-商家：0x1|0x4，0x2|0x4）</param>
		/// <param name="Memo">备注</param>
		/// <param name="RelevanceId">相关ID（DingID等）</param>
		/// <param name="RelevanceUserId">相关用户ID</param>
		IFinanceFactory AddLog(int CusId, int Type, decimal Amount, int Currentcy, string Memo, int RelevanceId, int RelevanceUserId);

		/// <summary>
		/// 添加日志（使用事务）
		/// </summary>
		/// <param name="context"></param>
		/// <param name="CusId">账户变动的用户</param>
		/// <param name="Type">变动类型，单数为增加，偶数为减少</param>
		/// <param name="Amount">金额（无论增减都是正数）</param>
		/// <param name="Currentcy">货币类型（0x1-线上，0x2-线下，0x4-商家：0x1|0x4，0x2|0x4）</param>
		/// <param name="Memo">备注</param>
		/// <param name="RelevanceId">相关ID（DingID等）</param>
		/// <param name="RelevanceUserId">相关用户ID</param>
		/// <returns></returns>
		IFinanceFactory AddLog(IDbContext context, int CusId, int Type, decimal Amount, int Currentcy, string Memo, int RelevanceId, int RelevanceUserId);

		/// <summary>
		/// 开始事务，批量修改数据的时候请使用
		/// </summary>
		/// <returns></returns>
		IDbContext BeginTransaction();

		/// <summary>
		/// 保存数据，如果发生异常会抛出错误
		/// </summary>
		/// <returns></returns>
		int SaveData(IDbContext context);
	}

	public interface IBalance {
		int CusId { get; }
		IEnumerable<KeyValuePair<string, decimal>> Amounts { get; }
	}
}
